package es.ucm.fdi.isbc.viviendas.representacion.similitud;

import jcolibri.exception.NoApplicableSimilarityFunctionException;
import jcolibri.method.retrieve.NNretrieval.similarity.LocalSimilarityFunction;

public class SimilitudNumericaUnivaluada implements LocalSimilarityFunction {

	/**
	 * Comparamos caseObject con queryObject
	 * 
	 * Si ambos estan en rangos similares, similitud 1,
	 * si estan en rangos distintos y anexos, similitud 0.6,
	 * si estan en rangos opuestos, similitud 0.1
	 */
	public double compute(Object caseObject, Object queryObject)
			throws NoApplicableSimilarityFunctionException {
		if(caseObject==null || queryObject==null){
			return 0.0;
		}		
		double valor=0;
		
		if ((Integer)caseObject >5 ){
			if ((Integer)queryObject > 5){
				valor=1;
			}else if ((Integer)queryObject > 2){
				valor=0.6;
			}else if ((Integer)queryObject > 0){
				valor=0.1;
			}
			
		}else if ((Integer)caseObject >5 && (Integer)queryObject > 2){
			if ((Integer)queryObject > 5){
				valor=0.6;
			}else if ((Integer)queryObject > 2){
				valor=1;
			}else if ((Integer)queryObject > 0){
				valor=0.6;
			}
		}else if ((Integer)caseObject >5 && (Integer)queryObject > 0){
			if ((Integer)queryObject > 5){
				valor=0.1;
			}else if ((Integer)queryObject > 2){
				valor=0.6;
			}else if ((Integer)queryObject > 0){
				valor=1;
			}
		}
		

		return valor;
	}

	/**
	 * Deberia ser aplicable solamente a los integer
	 */
	public boolean isApplicable(Object caseObject, Object queryObject) {

		return (caseObject instanceof Integer && queryObject instanceof Integer);
	}

}
